package interfaces.impl;

import interfaces.ActionInterface;
import objects.WorldObject;
import universe.Universe;
import constants.Constants;

public abstract class Action implements ActionInterface {
	
	protected WorldObject source=null; ///is possible to use a list but now i just use one source and one target
	protected WorldObject target=null;  // 
	
	protected int priority=0;
	protected String name;
	protected int id;
	protected double executeTime=0;  
	protected double waitTimeToExecute=0;
	protected boolean isActive=false;
	
	public Action(){
		source=null;
		target=null;
		priority=Constants.NO_PRIORITY;
		this.id=Constants.NO_ACTION;
		initializeId();
		initializeName();
		isActive=false;
		
	}
	
	

	public Action(int priority){
		source=null;
		target=null;
		this.id=Constants.NO_ACTION;
		initializeId();
		initializeName();
		this.priority=priority;
		isActive=false;
	}
	
	
	public boolean processAction(Universe universe){
		
		if(source==null || target == null ){
			System.out.println("Targer o Source nulos en la accion "+name);
			return false;
		}
		
		return processActionChild(universe);
	}
	
	public WorldObject getSource() {
		return source;
	}

	public void setSource(WorldObject source) {
		this.source = source;
	}

	public WorldObject getTarget() {
		return target;
	}

	public void setTarget(WorldObject target) {
		this.target = target;
	}

	public int getPriority() {
		return priority;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

	public String getName(){
		return name;
	} 

	public void setName(String name) {
		this.name = name;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	
	
	public double getExecuteTime() {
		return executeTime;
	}

	public void setExecuteTime(double executeTime) {
		this.executeTime = executeTime;
	}

	public double getWaitTimeToExecute() {
		return waitTimeToExecute;
	}

	public void setWaitTimeToExecute(double waitTimeToExecute) {
		this.waitTimeToExecute = waitTimeToExecute;
	}
	@Override 
	public void modifyAction(ActionInterface action){
		
		 this.source=action.getSource();
		 this.target=action.getTarget();
		 this.id=action.getId();
		 this.priority=action.getPriority();
		 this.isActive=action.isActive();
		 this.modifyChild(action);
	}
	
	
	@Override
	public int compareTo(ActionInterface o) {
		/*if(this.getId() == o.getId())
			return 0;*/
		
		if(this.priority<o.getPriority()){
			return -1;
		}
		if(this.priority>o.getPriority()){
			return 1;
		}
		return 1;
		
	}
	
	public boolean isActive(){
		return isActive;
	}
	
	public void setActive(boolean active){
		System.out.println("Me activaron "+name);
		isActive=active;
	}



	public abstract void modifyChild(ActionInterface action);



	public abstract boolean processActionChild(Universe universe);



	public abstract void initializeName();



	public abstract void initializeId();
	
	

}
